package com.itwn.portal.controller;

import com.itwn.portal.model.entity.China;
import com.itwn.portal.model.vo.AddressVo;
import com.itwn.portal.service.AddressService;
import com.itwn.portal.service.ChinaService;
import com.itwn.portal.util.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/china")
@Api(tags = "省市区管理")
public class ChinaController {

    @Autowired
    private ChinaService chinaService;

    @ApiOperation("获取所有的省份")
    @GetMapping("/getAllProvince")
    public ResponseEntity<List<China>> getAllProvince(){
        // 使用缓存优化
        List<China> result = chinaService.getAllProvince();
        return ResponseEntity.ok(result);
    }

    @ApiOperation("根据省份的id查询所有城市")
    @GetMapping("/getAllCities")
    public ResponseEntity<List<China>> getAllCities(Integer provinceId){
        List<China> result = chinaService.getAllCities(provinceId);
        return ResponseEntity.ok(result);
    }

    @ApiOperation("根据城市id查询区/县")
    @GetMapping("/getAllDistricts")
    public ResponseEntity<List<China>> getAllDistricts(Integer cityId){
        List<China> result = chinaService.getAllDistricts(cityId);
        return ResponseEntity.ok(result);
    }
}
